package code.rocky.threadlocal;

import java.util.concurrent.TimeUnit;

public class ThreadLocalDemo04 {

    static ThreadLocal<String> threadLocal = new InheritableThreadLocal<String>();


    public static void main(String[] args) {
        threadLocal.set(Thread.currentThread().getName());
        System.out.println(Thread.currentThread().getName() + " 线程获取到: " + threadLocal.get());
        Thread t1 = new Thread(()->{
            System.out.println(Thread.currentThread().getName() + " 线程获取到: " + threadLocal.get());
        },"t1");
        t1.start();

        try {
            TimeUnit.SECONDS.sleep(1);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
